<template>
    <div style="margin-top:40px">
        <div class="ODdiv2">
            <span>订单概况</span>
        </div>
        <div class="ODdiv3">
            <span>订单号：{{OrderNum}}</span>
            <span class="div3span1">状态：</span>
            <span class="div3span2">{{Status==0?'已取消':'已支付'}}</span>
        </div>
        <div>
            <span class="div3span3">下单时间：{{orderTime}}</span>
        </div>
        <div class="ODdiv4" v-show="!Status">
            <span>
                <i class="el-icon-warning-outline" style="color:rgb(30, 154, 255); font-size:150%;
                margin-left:6px;margin-right:10px"></i>
                您的订单已取消，欢迎您再次购买。
            </span>
        </div>
        <div class="ODdiv4" v-show="Status" style="background-color: rgb(237, 255, 235);border: 1px solid rgb(178, 255, 178);">
            <span>
                <i class="el-icon-circle-check" style="color:rgb(30, 255, 41); font-size:150%;
                margin-left:6px;margin-right:10px"></i>
                您的订单已支付，欢迎您再次购买。
            </span>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
    export default {
        name:'PxODSUp',
        data(){
            return{
                RouterOid:'',
                MyOidData:[{'orderTime':''}],
                orderTime:'',
                OrderNum:'',
                Status:0,
                payTime:'',
            }
        },
        mounted(){
            if(sessionStorage.getItem('OrderDetailsOIDdate') !=null){  //如果sessionStorage里的数据存在时
                if(this.$route.params.oid != null) {   //如果路由有传来数据(到达订单详情页面),此时是没有关闭已经存在的的订单详情页面而进行的路由跳转
                    if(this.$route.params.oid != sessionStorage.getItem('OrderDetailsOIDdate')){
                    this.RouterOid = this.$route.params.oid
                    sessionStorage.setItem('OrderDetailsOIDdate',JSON.stringify(this.RouterOid))
                    console.log('111session数据存在route数据也存在');
                    }else{
                        this.RouterOid=JSON.parse(sessionStorage.getItem('OrderDetailsOIDdate'))
                        console.log('222session数据存在route数据也存在且相等');
                    }
                }
                else{
                    //如果路由没有传数据(路由没有跳转)      此时解释为刷新页面
                    this.RouterOid=JSON.parse(sessionStorage.getItem('OrderDetailsOIDdate'))
                    console.log('333session数据存在route数据不存在为null');
                }
            }else{	    //如果sessionStorage里没有数据(即路由有跳转)    此时解释为初次进入订单详情界面
                this.RouterOid = this.$route.params.oid
                sessionStorage.setItem('OrderDetailsOIDdate',JSON.stringify(this.RouterOid))
                console.log('444session不存在route数据存在');
            }
            this.$addr.get(`orders/`).then(
                response=>{
                    console.log('请求获取订单信息成功',response)
                    for( let i =0,j =0; i<response.data.data.length ; i++){
                        if(response.data.data[i].oid == this.RouterOid){
                            this.MyOidData[j]=response.data.data[i]
                            j++
                        }
                    }
                    this.OrderNum=this.MyOidData[0].onum
                    this.orderTime=this.MyOidData[0].orderTime
                    this.payTime=this.MyOidData[0].payTime
                    this.Status=this.MyOidData[0].status
                    this.$bus.$emit('MyOidData',this.MyOidData)
                    this.$bus.$emit('orderandpayTime',this.orderTime,this.payTime)
                    this.$bus.$emit('Status',this.Status)
                },
                error=>{
                    console.log('请求获取订单信息失败',error.message)
                }
            )
        },
    }
</script>

<style scoped>
.ODdiv2{
    padding: 10px;
    padding-left: 15px;
    background-color: rgb(246, 246, 246);
    border-bottom: 1px solid rgb(201, 201, 201);
    font-size: 14px;
}
.ODdiv3{
    font-size: 13px;
    padding-top: 25px;
    padding-left: 20px;
    padding-right: 20px;
}
.div3span1{
    margin-left: 35px;
}
.div3span2{
    font-weight: 550;
    color: rgb(109, 109, 109);
}
.div3span3{
    margin-left: 20px;
    font-size:12px
}
.ODdiv4{
    margin-right: 22px;
    margin-left: 22px;
    margin-top: 10px;
    background-color: rgb(228, 243, 255);
    font-size: 12px;
    padding: 8px;
    border: 1px solid rgb(178, 209, 255);
}
</style>